﻿using CommunityToolkit.Mvvm.DependencyInjection;
using Enterprises.Wpf.Sample.Registrar;
using Enterprises.Wpf.Sample.ViewModel.Main;
using Microsoft.Extensions.DependencyInjection;
using System.Configuration;
using System.Data;
using System.Windows;

namespace Enterprises.Wpf.Sample
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        public App()
        {
            // IOC方式一
            Services = ConfigureServices();

            // IOC方式二，注入到默认容器中.
            Ioc.Default.ConfigureServices(
                new ServiceCollection()
                .AddTransient<RelayCommandDemoCtlViewModel>()
                .BuildServiceProvider());

            this.InitializeComponent();
        }

        /// <summary>
        /// Gets the current <see cref="App"/> instance in use
        /// </summary>
        public new static App Current => (App)Application.Current;

        /// <summary>
        /// Gets the <see cref="IServiceProvider"/> instance to resolve application services.
        /// </summary>
        public IServiceProvider Services { get; }

        /// <summary>
        /// Configures the services for the application.
        /// </summary>
        private static IServiceProvider ConfigureServices()
        {
            var services = new ServiceCollection();
            services = services.Registrar();
            return services.BuildServiceProvider();
        }
    }

}
